﻿@using System.Data
@using Microsoft.Ajax.Utilities
@{
    ViewBag.Title = "支付";
    Layout = "~/Areas/Mall/Views/Shared/MallLayout1.cshtml";
    var set = ViewData["orderinfo"] as DataSet;
    var table = ViewData["address"] as DataTable;
    var orderno = set.Tables[0].Rows[0]["OrderNo"];//单号
    var time = set.Tables[0].Rows[0]["Date"].ToString().Substring(0, 10);//时间
    var totalPrice = Convert.ToDouble(set.Tables[0].Rows[0]["TotalPrice"]);//总价
    var freight = Convert.ToDouble(set.Tables[0].Rows[0]["Freight"]);//运费
    var count = 0;
    var alljf = ViewData["alljf"];
}
<div class="order_list">
    <div class="order_info">
        <label style="float: left;">订单号：@orderno</label>
        <label style="float: right;">下单时间：@time</label>
    </div>
    @{
        foreach (DataRow row in set.Tables[1].Rows)
        {
            count += Convert.ToInt32(row["Count"].ToString());
            var price = Convert.ToDouble(row["Price"]) * Convert.ToDouble(row["Count"]);
            <div class="order_g">
                <img src="@row["Img1"]">
                <div>
                    <p>@row["Name"]</p><p>@row["Attr"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
                    <p>数量：@row["Count"]</p><p class="orderxj">小计：@price 元</p>
                </div>
            </div>
        }
    }


    <div class="ordert_j">
        <p style="text-align: right;">共 @count 件商品 合计￥@totalPrice 元(含运费￥@freight)</p>
    </div>
</div>

<div class="ad_tl">
    收货地址列表
</div>
<div class="ad_tl">
    <select style="width: 98%;height: 20px;">
        <option value="0">请选择收货地址</option>
        @{
            var defalultadd = "";
            var addid = 0;
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    if (row["Default"].ToString() == "1")
                    {
                        defalultadd = row["Address"].ToString();
                        addid = Convert.ToInt32(row["Id"]);
                    }
                    <option value="@row["Id"]">@row["Address"]</option>
                }
                addid = addid == 0 ? Convert.ToInt32(table.Rows[0]["Id"].ToString()) : addid;
                defalultadd = defalultadd == "" ? table.Rows[0]["Address"].ToString() : defalultadd;
            }

        }
    </select>
</div>
<div class="add_od_s">
    当前收货地址
</div>
<div class="ad_tl">
    <strong id="add_" addid="@addid">@defalultadd</strong>
</div>
<div class="ad_tl">
    <a href="@Url.Action("Address","Center")" style="color: #ff0000;">添加收货地址</a>
</div>
<div class="ad_tl" style="margin-top: 30px;">
    <div class="pay">
        微信支付
    </div>
</div>
<div style="width: 100%;height: 100px;float: left;"></div>

<script>
    $(function () {

    });
    $(".pay").click(function () {
        var addid = $("#add_").attr("addid");
        if (addid == 0) {
            alert("请添加收货地址！");
            return false;
        } else {
            $.post("@Url.Action("EditAdd")", { addid: addid, orderno: "@ViewData["orderno"]" }, function (row) {
                if (row > 0) {
                    $.post("@Url.Action("EditOrderStatus")", { orderid: "@ViewData["orderno"]", value: 2 }, function (row1) {
                        if (row > 0) {
                            alert("支付成功！");
                            location.href = "/mall/order/orderlist?sid=2";
                        }
                    });

                } else {
                    location.reload();
                }
            });

        }

    });

</script>
